package com.yisu.auction.ewf.common.utils;

import com.yisu.auction.ewf.common.web.HttpWebClient;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * Created by Administrator on 2016/8/25.
 */
public class ValidateCodeUtil {

    public static String generate(int length) {
//        String str = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
        String candidateChar = "0,1,2,3,4,5,6,7,8,9";
        String[] candidateCharArray = candidateChar.split(",");
        Random rand = new Random();
        StringBuilder randStr = new StringBuilder(4);
        int candidateCharCount = candidateCharArray.length -1;
        for (int i = 0; i < length; i++) {
            int index = rand.nextInt(candidateCharCount);
            randStr.append(candidateCharArray[index]);
        }
        return randStr.toString();
    }

    public static String sendMengWangMessage(String url, SpMessage message) {
        Map<String, String> params = new HashMap<>();
        params.put("userId", message.getUserId());
        params.put("password", message.getPassword());
        params.put("pszMobis", message.getMobile());
        params.put("pszMsg", message.getMessage());
        params.put("iMobiCount", String.valueOf(message.getMobileCount()));
        params.put("pszSubPort", "*");
        params.put("MsgId", String.valueOf(System.currentTimeMillis()));

        return HttpWebClient.post(url, params);
    }

    public static String sendYunPianMessage(String url, YunPianMessage message) {
        Map<String, String> params = new HashMap<>();
        params.put("apikey", message.getApiKey());
        params.put("mobile", message.getMobile());
        params.put("text", message.getText());
        return HttpWebClient.post(url, params);
    }
}
